package com.service;

import com.Dao.ArticleDao;
import com.bean.Article;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class ArticleService {
    ArticleDao dao=new ArticleDao();
    Article article=new Article();

    //添加文章
    public void add(Article article)  {
        try {
            dao.addArticle(article);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            System.out.println("添加文章失败！！！");
        }
    }

    //删除文章
    public void  delete(String title){
        try {
            dao.deleteArticleByTitle(title);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            System.out.println("删除文章失败！！！");
        }
    }

    public int querycount(String typename){
        int count=0;
        try{
            count=dao.querycount(typename);
        }catch (Exception e){
            e.printStackTrace();
        }
        return count;
    }
    /**
     * 查找
     * @param id
     * @return
     */
    //根据文章标题查找文章
    public Article findByTitle(String title) throws SQLException {
        return  dao.findArticleByTitle(title);
    }

    public List<Article> findByType(String type) throws SQLException {
           return dao.findArticleByType(type);
    }

    public Article find(int id) throws SQLException {
        return dao.findArticleById(id);
    }
    //获取所有类型中文章的数量
    public int findAllCnt(String typename){
        int count=0;
        try {
             count= dao.findAllCount(typename);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            System.out.println("获取类型数据失败！！！");
        }
        return count;
    }
    //获取所有文章
    public List<Article> getAllArticle() throws SQLException {
        return dao.getAllArticle();
    }
    //获取发表时间
    public Date getPubTime(String title) throws SQLException {
        return dao.findPubTime(title);
    }

    //按照阅读量获取文章
    public List<Article> getMaxCount() throws SQLException {
        return dao.findMaxCount();
    }




}
